package service

import (
	"dc-news-admin-api/common/global/consts"
	"dc-news-admin-api/common/resp"
	"dc-news-admin-api/common/utils"
	"dc-news-admin-api/dao"
	"dc-news-admin-api/vo"
	"github.com/gin-gonic/gin"
	"net/http"
)

func GetUserListService(c *gin.Context) {
	p := utils.NewPagination(c)
	users, err := dao.GetUserListByPage(p)
	if err != nil {
		c.JSON(http.StatusOK, resp.NewErrResp(consts.FailCode, "获取失败"))
		return
	}
	c.JSON(http.StatusOK, vo.NewGetUserListResp(users, p))
}

func DeleteUserService(c *gin.Context, id int) {
	err := dao.DeleteUserById(id)
	if err != nil {
		c.JSON(http.StatusOK, resp.NewErrResp(consts.FailCode, "操作失败"))
		return
	}
	c.JSON(http.StatusOK, resp.NewOkResp())
}

func SetUserMuteStatusService(c *gin.Context, id int, req *vo.SetUserMuteStatusReq) {
	err := dao.MuteUserById(id, req.IsMuted)
	if err != nil {
		c.JSON(http.StatusOK, resp.NewErrResp(consts.FailCode, "操作失败"))
		return
	}
	c.JSON(http.StatusOK, resp.NewOkResp())
}
